from machine import Pin, Timer
import utime

# 创建定时器对象
timer = Timer(0)

# 创建LED对象
led = Pin(16, Pin.OUT, value=0)
led_val = 0

# 定时器中断处理函数
# 必须传入定时器对象
def led_handler(timer):
    global led_val
    led_val = not led_val
    led.value(led_val)

if __name__ == "__main__":
    # 使用定时器中断控制LED每1s闪烁一次
    timer.init(period=500, mode=Timer.PERIODIC, callback=led_handler)
    
    while True:
        pass

